package org.chen.wordwave.act.game;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.chen.wordwave.R;
import org.chen.wordwave.act.game.GameBoard;
import org.chen.wordwave.base.BaseActivity;
import org.chen.wordwave.bean.Configs;

public class Game extends BaseActivity {
    private TextView bestTxt,game_rules;
    private SharedPreferences prefs;

    @Override
    public Integer getLayoutResId() {
        return R.layout.home_act;
    }

    @Override
    public void init() {
        super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

        bestTxt = (TextView)findViewById(R.id.hBestTxt);
        game_rules = (TextView)findViewById(R.id.game_rules);
        bestTxt.setTypeface(Configs.juneGull);


        prefs = PreferenceManager.getDefaultSharedPreferences(Game.this);
        Configs.bestScore = prefs.getInt("bestScore", Configs.bestScore);
        bestTxt.setText(String.valueOf(Configs.bestScore));


        // - 开始按钮
        Button playButt = (Button)findViewById(R.id.hPlayButt);
        playButt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(Game.this, GameBoard.class));
            }});

        game_rules.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showRulesDialog();
            }
        });
    }

    private void showRulesDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.game_info_game);
        builder.setMessage(R.string.game_info_game_rules);
        builder.setPositiveButton(R.string.yes, (dialog, id) -> dialog.dismiss());
        AlertDialog dialog = builder.create();
        dialog.show();
    }
}
